{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. URL\n",
    "FaceSet_getfacesets_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets'\n",
    "\n",
    "\n",
    "# 2. api账号/通行证\n",
    "API_key = 'JAGR_NQMxTZWeRCq_7UV6QC8Eq2uSe-p'\n",
    "API_secret = '8c0DvbbGq8DZesE9peYVPjrskuvI5y36'\n",
    "\n",
    "\n",
    "# 3. 请求方法：POST\n",
    "\n",
    "\n",
    "# 4. 准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret\n",
    "}\n",
    "\n",
    "\n",
    "# 5. 发起请求\n",
    "r = requests.post(url = FaceSet_getfacesets_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'{\"time_used\": 70, \"facesets\": [{\"faceset_token\": \"12bcf283beccdd7b480d13304f2ccca8\", \"outer_id\": \"\", \"display_name\": \"\", \"tags\": \"\"}], \"request_id\": \"1648469107,17b00ac9-35ee-419f-aeee-da5541c8b59d\"}'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 70,\n",
       " 'facesets': [{'faceset_token': '12bcf283beccdd7b480d13304f2ccca8',\n",
       "   'outer_id': '',\n",
       "   'display_name': '',\n",
       "   'tags': ''}],\n",
       " 'request_id': '1648469107,17b00ac9-35ee-419f-aeee-da5541c8b59d'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " # 3. 更新人脸库信息API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "faceset_token = r.json()['facesets'][-1]['faceset_token']# 取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "face_detect = r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. URL\n",
    "FaceSet_update_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/update'\n",
    "\n",
    "\n",
    "# 2. api账号/通行证\n",
    "API_key = 'JAGR_NQMxTZWeRCq_7UV6QC8Eq2uSe-p'\n",
    "API_secret = '8c0DvbbGq8DZesE9peYVPjrskuvI5y36'\n",
    "\n",
    "\n",
    "# 3. 请求方法：POST\n",
    "\n",
    "\n",
    "# 4. 准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'faceset_token':faceset_token,\n",
    "    'display_name':'广州南方学院0栋学生宿舍楼',\n",
    "    'new_outer_id':'NFUSD00',\n",
    "    'user_data':'6层，满员，女生宿舍，460位同学，均已录入face_token'\n",
    "}\n",
    "\n",
    "\n",
    "# 5. 发起请求\n",
    "r = requests.post(url = FaceSet_update_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '12bcf283beccdd7b480d13304f2ccca8',\n",
       " 'request_id': '1648470218,1f6fabc8-492f-4bb4-b84d-82032dafaa5e',\n",
       " 'time_used': 85,\n",
       " 'outer_id': 'NFUSD00'}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. URL\n",
    "FaceSet_getdetail_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail'\n",
    "\n",
    "\n",
    "# 2. api账号/通行证\n",
    "API_key = 'JAGR_NQMxTZWeRCq_7UV6QC8Eq2uSe-p'\n",
    "API_secret = '8c0DvbbGq8DZesE9peYVPjrskuvI5y36'\n",
    "\n",
    "\n",
    "# 3. 请求方法：POST\n",
    "\n",
    "\n",
    "# 4. 准备payload（酬载）\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'faceset_token':faceset_token\n",
    "}\n",
    "\n",
    "\n",
    "# 5. 发起请求\n",
    "r = requests.post(url = FaceSet_getdetail_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '12bcf283beccdd7b480d13304f2ccca8',\n",
       " 'tags': '',\n",
       " 'time_used': 92,\n",
       " 'user_data': '6层，满员，女生宿舍，460位同学，均已录入face_token',\n",
       " 'display_name': '广州南方学院0栋学生宿舍楼',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1648470612,43527115-fff6-466d-b3b2-8923d2076825',\n",
       " 'outer_id': 'NFUSD00'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import detect"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
